package com.gdit.revenue.controller;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.gdit.revenue.base.result.Results;
import com.gdit.revenue.model.Income;
import com.gdit.revenue.service.IncomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/income")
public class IncomeController {
    //这个就开始AOP面向切面编程
    private static final Log log = LogFactory.getLog(IncomeController.class);

    @Autowired
    IncomeService incomeServiceImpl;
    @RequestMapping("/incomelist")
    @ResponseBody   //解析Json数据
    public Results incomelist(int page, int limit){
        log.warn("用户调用了/income/incomelist");    //日志
        int start = (page-1)*limit;     //第几个数据开始展示
        return incomeServiceImpl.getAllIncome(start,limit);
    }

    @RequestMapping("/addincome")
    public String addincome(){
        return "/income/addincome";
    }

    @RequestMapping("/updateincome")
    public String updateincome(){
        return "/income/updateincome";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Results delete(int inId){
        return incomeServiceImpl.delete(inId);
    }

    @PostMapping("/addIncome")
    @ResponseBody
    public int addIncome(@RequestBody Income income){
        incomeServiceImpl.addIncome(income);
        return 0;
    }

    @PostMapping("/updateIncome")
    @ResponseBody
    public Results updateIncome(@RequestBody Income income){
        return incomeServiceImpl.updateIncome(income);
    }

}